// Mesh Scene Node
// (c) jimon game studio

#ifndef JEH_CMESHSCENENODE
#define JEH_CMESHSCENENODE

#include "IMeshSceneNode.h"
#include "ISceneManager.h"
#include "CSkinnedMesh.h"

namespace je
{
	namespace scene
	{
		//! Mesh Scene Node
		class CMeshSceneNode:public je::scene::IMeshSceneNode
		{
		protected:
			scene::ISceneManager * CurrentSceneManager;
			media::jeSharedMesh * CurrentSharedMesh;
			u1 CurrentUseUniqueMesh;
			f32 MeshRadius;

			u1 EnableAnimation;
			CSkinnedMesh * SkinnedMesh;
			MeshAnimation CurrentAnimation;
			u1 NeedRecalculateAnimation;
		public:
			//! Constructor
			CMeshSceneNode(video::IRender * Render,scene::ISceneManager * SceneManager);

			//! Destructor
			~CMeshSceneNode();

			//! Set Animation
			void SetAnimation(MeshAnimation & Animation)
			{
				if((CurrentAnimation.Id != Animation.Id) || (CurrentAnimation.Time != Animation.Time))
					NeedRecalculateAnimation = true;

				CurrentAnimation = Animation;
			}

			//! Get Animation
			MeshAnimation & GetAnimation()
			{
				return CurrentAnimation;
			}

			//! Set Mesh Resource
			void SetMeshResource(media::jeMeshResource * MeshResource,u1 UseUniqueMesh = false);

			//! Get Mesh Resource
			media::jeMeshResource * GetMeshResource();

			//! Get Shared Mesh Resource
			media::jeSharedMesh * GetSharedMeshResource();

			//! On Update
			void OnUpdate();

			//! On Render
			void OnRender();

			//! On Visibility Culling
			void OnVisibilityCulling();

			//! Serialize
			void Serialize(core::ISerializeStream * SerializeStream);

			//! Get Node Type Name
			jeStringc GetNodeTypeName()
			{
				return jeStringc("MeshSceneNode");
			}
		};
	}
}

#endif
